﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DirectSell.Model.User;
using Direct.IDAL.User.Money;
using DirectSell.Model.Money;
using Direct.IDAL.User.Jurisdiction;

namespace DirectSell.BLL.User.Money
{
    /// <summary>
    /// 电子币操作
    /// </summary>
    public class VirtualMoneyService:UserService
    {
        #region 日志记录
        /// <summary>
        /// 日志记录
        /// </summary>
        protected override string LogFile
        {
            get
            {
                return "电子币申请";
            }
        }
        #endregion

        #region 构造函数
        /// <summary>
        /// 电子币数据操作接口
        /// </summary>
        protected IVirtualMoneyRepository _virtualMoney { get; set; }
        /// <summary>
        /// 判断二级密码
        /// </summary>
        protected IModifyInfoRespository _modifyInfoRepository { get; set; }
        public VirtualMoneyService(IVirtualMoneyRepository virtualMoney, IModifyInfoRespository modifyInfoRepository)
        {
            this._modifyInfoRepository = modifyInfoRepository;
            this._virtualMoney = virtualMoney;
        }
        #endregion

        #region 申请电子币
        /// <summary>
        /// 操作入口
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="param"></param>
        /// <returns></returns>
        protected async override Task<UserRespCode> OperationAsync<T>(T param)
        {
            var model = param as VirtualMoneyReq;

            if (model == null)
            {
                return UserRespCode.传入参数不正确;
            }

            if (! await _modifyInfoRepository.CheckSecondPassword(model.UserCode, model.SecondPassWord))
            {
                return UserRespCode.二级密码输入错误;
            }

            await LogAsync(model);

            if (!_virtualMoney.Apply(model))
            {
                return UserRespCode.失败;
            }

            return UserRespCode.成功;
        }
        #endregion
    }
}
